﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Common.Net.Utilities;
using ClearUnit.TestRunners;

namespace ClearUnit.Tests
{
    public class Program
    {
        public static void Main()
        {
            int totalRun = 0;
            int failed = 0;
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
                foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                    if (method.HasAttribute<TestAttribute>())
                        try
                        {
                            totalRun++;
                            Console.WriteLine("Running test {0}.{1}...", type.Name, method.Name);

                            var instance = Activator.CreateInstance(type);
                            method.Invoke(instance, null);
                        }
                        catch (Exception ex)
                        {
                            failed++;
                            Console.WriteLine(ex.ToString());
                        }

            Console.WriteLine("Total run: {0}, failed: {1}", totalRun, failed);

            Console.WriteLine("Press ENTER to finish");
            Console.ReadLine();
        }
    }
}
